Ext.define('AmpleHarvest.objects.classification.cPanel',
{
	extend						: 'Ext.container.Container',
	alias						: 'widget.ampleharvest-objects-classification-cpanel',
	requires					:
	[
			"Ext.form.field.ComboBox",
			"AmpleHarvest.DATA.Store.cClassification"
	],
//	uses						: [
//	 'DarkOwl.User_Manager.Windows.Setup.cCreateDB',
//	],
	bodyStyle					: 'padding:0px',
	layout						: 'hbox',
	m_bool_Editable				: false,
	m_str_ClassificationName	: "Classification",
	m_str_SCIName				: "SCI",
	m_str_DistroName			: "Distro",
	m_str_ClassificationInit	: "",
	m_str_SCIInit				: "",
	m_str_DistroInit			: "",
	frame						: true,

	initComponent				: function()
	{
		var obj_This = this;
		this.callParent();

		this.m_obj_Classification = Ext.create("Ext.form.field.ComboBox",
		{
			fieldLabel		: "Classification",
			labelAlign		: "top",
			name			: this.m_str_ClassificationName.toLowerCase(),
			hiddenName		: this.m_str_ClassificationName.toLowerCase(),
			disabled		: false,
			readOnly		: !this.m_bool_Editable,
			store			: Ext.create("AmpleHarvest.DATA.Store.cClassification"),
			grow			: true,
			minChars		: 1,
			flex			: 1,
			displayField	: 'Title',
			valueField		: 'Title',
			allowBlank		: false,
			readOnly		: !this.m_bool_Editable,
			autoSelect		: true,
			typeAhead		: true,
			queryMode		: 'remote',
			forceSelection	: true,
			triggerAction	: 'all',
			// emptyText:'Status?',
			selectOnFocus	: true
		}
		);
		this.add(this.m_obj_Classification);
		this.m_obj_Classification.store.setType("class");

		this.m_obj_SCI = Ext.create("Ext.form.field.ComboBox",
		{
			fieldLabel		: "SCI",
			labelAlign		: "top",
			name			: this.m_str_SCIName.toLowerCase(),
			hiddenName		: this.m_str_SCIName.toLowerCase(),
			disabled		: false,
			flex			: 1,
			readOnly		: !this.m_bool_Editable,
			store			: Ext.create("AmpleHarvest.DATA.Store.cClassification"),
			grow			: true,
			minChars		: 1,
			displayField	: 'Title',
			valueField		: 'Title',
			allowBlank		: true,
			readOnly		: !this.m_bool_Editable,
			autoSelect		: true,
			typeAhead		: true,
			queryMode		: 'remote',
			forceSelection	: true,
			triggerAction	: 'all',
			// emptyText:'Status?',
			selectOnFocus	: true
		}
		);
		this.add(this.m_obj_SCI);
		this.m_obj_SCI.store.setType("sci");
		this.m_obj_Classification.on("change", function(obj_Field, str_NewValue, str_OldValue)
				{
					this.m_obj_SCI.store.setClassification(str_NewValue);
					this.m_obj_SCI.doQuery("1", true);
					this.m_obj_SCI.collapse();
				}, this);

		this.m_obj_Distro = Ext.create("Ext.form.field.ComboBox",
				{
					fieldLabel		: "Distro",
					labelAlign		: "top",
					name			: this.m_str_DistroName.toLowerCase(),
					hiddenName		: this.m_str_DistroName.toLowerCase(),
					disabled		: false,
					readOnly		: !this.m_bool_Editable,
					store			: new AmpleHarvest.DATA.Store.cClassification(),
					grow			: true,
					minChars		: 1,
					flex			: 1,
					displayField	: 'Title',
					valueField		: 'Title',
					allowBlank		: true,
					readOnly		: !this.m_bool_Editable,
					autoSelect		: true,
					typeAhead		: true,
					queryMode		: 'remote',
					forceSelection	: true,
					triggerAction	: 'all',
					// emptyText:'Status?',
					selectOnFocus	: true
				}
		);
		this.add(this.m_obj_Distro);
		this.m_obj_Distro.store.on("expand", function(obj_Event)
				{
					alert("Loaded Data Store;" + obj_Event.combo.getValue());
				});
		this.m_obj_Distro.store.setType("distro");
		this.m_obj_Classification.on("change", function(obj_Field, str_NewValue, str_OldValue)
		{
			this.m_obj_Distro.originalValue = this.m_str_DistroInit;
			this.m_obj_Distro.store.setClassification(str_NewValue);
			this.m_obj_Distro.doQuery("1", true);
			this.m_obj_Distro.collapse();
				// this.m_obj_Distro.setValue(this.m_obj_Distro.getValue(),true);
			}, this
		);
	},

	initDropDowns				: function()
	{
		this.m_obj_Classification.doQuery("1", true);
		this.m_obj_Classification.collapse();
	},

	setInitClass				: function(str_Data)
	{
		this.m_str_ClassificationInit = str_Data;
	},

	setInitSCI					: function(str_Data)
	{
		if (this.m_obj_SCI.store.loading)
		{
			Ext.Function.defer(this.setInitSCI, 10, this,
					[
						str_Data
					])
		}
		else
		{
			this.m_obj_SCI.setValue(str_Data);
		}
		this.m_str_SCIInit = str_Data;
	},

	setInitDistro				: function(str_Data)
	{
		if (this.m_obj_Distro.store.loading)
		{
			Ext.Function.defer(this.setInitDistro, 10, this,
					[
						str_Data
					])
		}
		else
		{
			this.m_obj_Distro.setValue(str_Data);
		}
		this.m_str_DistroInit = str_Data;
	},

	initClassification			: function()
	{
		this.m_obj_Distro.originalValue = this.m_str_DistroInit;
		this.m_obj_Classification.setValue(this.m_str_ClassificationInit, true);
		this.m_obj_Distro.setValue(this.m_str_DistroInit, true);
		this.m_obj_SCI.setValue(this.m_str_SCIInit, true);
	}
}
);